package state.group;

import java.io.Serializable;
import java.net.InetAddress;
import java.util.Hashtable;

public class GroupDispatcherState implements Serializable {

    public static final long serialVersionUID = 6806031459274732322L;

    public InetAddress personDispatcherAddress = null;
    public int personDispatcherListeningPort = -1;

    public byte maxFloors;

    public final Hashtable<Byte, ElevatorStruct> elevatorData;
    public final Hashtable<Byte, InetAddress> elevatorIPs;
    public final Hashtable<HallCall, Byte> hallCallMappings;

    public GroupDispatcherState()
    {
        elevatorData = new Hashtable<Byte, ElevatorStruct>();
        elevatorIPs = new Hashtable<Byte, InetAddress>();
        hallCallMappings = new Hashtable<HallCall, Byte>();
    }

    @Override
    public String toString()
    {

        String retVal = "<GroupDispatcherState: ";

        synchronized (this)
        {

            retVal += "personDispatcherAddress: " + personDispatcherAddress + "\n";
            retVal += "personDispatcherListeningPort: " + personDispatcherListeningPort + "\n";

            retVal += "maxFloors: " + maxFloors + "\n";

        }

        synchronized (elevatorData)
        {
            for (Byte b : elevatorData.keySet())
            {
                retVal += "elevator[" + b + "]: " + elevatorData.get(b) + "\n";
            }
        }

        synchronized (elevatorIPs)
        {
            for (Byte b : elevatorIPs.keySet())
            {
                retVal += "elevatorIP[" + b + "]" + elevatorIPs.get(b) + "\n";
            }
        }

        synchronized (hallCallMappings)
        {
            for (HallCall c : hallCallMappings.keySet())
            {
                retVal += "Mapping {" + c + ", " + hallCallMappings.get(c) + "\n";
            }
        }

        retVal += ">";

        return retVal;

    }

}
